#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm> // find_if
#include <sstream> // stringstream

using namespace std;

class Solution {
    bool match(string &word, string &pattern) {
        unordered_map<char, char> mp;
        for (int i = 0; i < word.length(); ++i) {
            char x = word[i], y = pattern[i];
            if (!mp.count(x)) {
                mp[x] = y;
            } else if (mp[x] != y) { // word 中的同一字母必须映射到 pattern 中的同一字母上
                return false;
            }
        }
        return true;
    }

public:
    vector<string> findAndReplacePattern(vector<string> &words, string &pattern) {
        vector<string> ans;
        for (auto &word: words) {
            if (match(word, pattern) && match(pattern, word)) {
                ans.emplace_back(word);
            }
        }
        return ans;
    }
};


void trimLeftTrailingSpaces(string &input) {
    input.erase(input.begin(), find_if(input.begin(), input.end(), [](int ch) {
        return !isspace(ch);
    }));
}

void trimRightTrailingSpaces(string &input) {
    input.erase(find_if(input.rbegin(), input.rend(), [](int ch) {
        return !isspace(ch);
    }).base(), input.end());
}

vector<string> stringToStringVector(string input) {
    vector<string> output;
    trimLeftTrailingSpaces(input);
    trimRightTrailingSpaces(input);
    input = input.substr(1, input.length() - 2);
    stringstream ss;
    ss.str(input);
    string item;
    char delim = ',';
    while (getline(ss, item, delim)) {
        output.push_back(item.substr(1, item.length() - 2));
    }
    return output;
}

string stringToString(string input) {
    trimLeftTrailingSpaces(input);
    trimRightTrailingSpaces(input);

    return input.substr(1, input.length() - 2);
}


string stringVectorToString(vector<string> list, int length1d = -1) {
    if (length1d == -1) {
        length1d = list.size();
    }
    if (length1d == 0) {
        return "[]";
    }

    string result1d;
    for (int index = 0; index < length1d; index++) {
        string s = list[index];
        result1d += s + ", ";
    }
    return "[" + result1d.substr(0, result1d.length() - 2) + "]";
}

int main() {
    string line;
    while (getline(cin, line)) {
        vector<string> words = stringToStringVector(line);

        getline(cin, line);
        string pattern = stringToString(line);

        vector<string> ret = Solution().findAndReplacePattern(words, pattern);

        string out = stringVectorToString(ret);
        cout << out << endl;
    }
    return 0;
}